package com.woniuxy.warehouse.controller;

import com.woniuxy.commons.entity.warehouse.IoWarehouse;

import com.woniuxy.commons.entity.warehouse.dto.TimeAndOrderDto;
import com.woniuxy.commons.result.Result;
import com.woniuxy.warehouse.service.StockInService;

import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:SHEAndme
 * @Todo:TODO 入库
 * @DateTime:2022/4/19 10:01
 **/
@RestController
@RequestMapping("/warehouse/stockin")
public class StockInController {

    @Resource
    private StockInService stockInService;

    @ApiOperation(value = "根据时间范围和单号查找 没有输出的时候查找全部")
    @PostMapping("/findAllByTimeAndOrder/{pageNum}/{pageSize}")
    public Result findAllByTimeAndOrder(@PathVariable("pageNum") Integer currentPage,
                                        @PathVariable("pageSize") Integer pageSize,
                                        @RequestBody TimeAndOrderDto timeAndOrderDto) {
        return stockInService.findAllByTimeAndOrder(currentPage,pageSize,timeAndOrderDto);
    }

    /**
     * TODO: 分页查询
     */
    @PostMapping("/findAll/{pageNum}/{pageSize}")
    public Result findAll(@PathVariable("pageNum") Integer currentPage,
                          @PathVariable("pageSize") Integer pageSize,
                          @RequestBody IoWarehouse ioWarehouse) {
        return stockInService.queryByPage(currentPage,pageSize,ioWarehouse);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @PostMapping("/findby/{id}")
    public Result queryById(@PathVariable("id") Integer id) {
        System.out.println("到达了queryById："+id);
        Result<List<IoWarehouse>> result = stockInService.queryById(id);
        return result;

    }

    /**
     * 新增数据
     *
     * @param ioWarehouse 实体
     * @return 新增结果
     */
    @ApiOperation(value = "新增入库单")
    @PostMapping("/addStockin")
    public Result add(@RequestBody IoWarehouse ioWarehouse) {
        return stockInService.insert(ioWarehouse);
    }

    /**
     * 编辑数据
     *
     * @param ioWarehouse 实体
     * @return 编辑结果  修改
     * TODO 暂时没地方使用
     */
    @PutMapping("/update")
    public Result edit(@RequestBody IoWarehouse ioWarehouse) {

        return stockInService.update(ioWarehouse);
    }

    /**
     * @param id 主键
     * @return 删除是否成功
     * TODO 根据主键永久删除数据  不建议使用
     */
    @DeleteMapping("/deleteby/{id}")
    public Result<Boolean> deleteById(@PathVariable("id") Integer id) {
        System.out.println("id:"+id);
        return Result.ok(stockInService.deleteById(id));
    }
    /**
     * @description TODO 逻辑删除 将状态改为0 0 为删除
     */
    @ApiOperation(value = "逻辑删除")
    @DeleteMapping("/logicDeleteById/{id}")
    public Result<Boolean> logicDeleteById(@PathVariable("id") Integer id) {
        System.out.println("id:"+id);
        return Result.ok(stockInService.logicDeleteById(id));
    }
}
